package com.servlet;
import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.user.User;

@WebServlet("/login")
public class Login extends HttpServlet {
	private static final long serialVersionUID = 1L;

	public Login() {
		super();
	}

	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {

		String form = request.getParameter("form");
		String ur = request.getParameter("username");
		String email = request.getParameter("email");
		String pwd = request.getParameter("pwd");
		response.setContentType("text/html");
		PrintWriter out = response.getWriter();
		System.out.println("Hello");
		
		if (form.equals("login")) {
			User user = new User(ur, email, pwd);
			if(user.checkUser())
				out.write("<H2>Login Sucessfully</h2>");
			else
				out.write("<H2>Login Failure</h2>");
			
		} else if (form.equals("signup")) {
			User user = new User(ur, email, pwd);
			if(user.saveUser())
				out.write("<H2>Signed up Sucessfully</h2>");
			else
				out.write("<H2>Sign up Failure</h2>");
		} 

			
			//out.write("<H2>Error </h2>");
	
	}

	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {

	}

}
